home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / 15 reflection / reflectiondemo / classes.vb < prev    next >
Encoding:
Text File  |  2001-12-29  |  1.3 KB  |  50 lines

  1. ' a class for our reflection tests
  2.  
  3. Class Person
  4.     ' Some public and private fields
  5.     Public FirstName As String
  6.     Public LastName As String
  7.  
  8.     Dim m_Age As Short
  9.     Dim m_EmailAddress(4) As String
  10.  
  11.     Sub New()
  12.         MyBase.New()
  13.     End Sub
  14.  
  15.     ' A constructor with parameters
  16.     Sub New(ByVal FirstName As String, ByVal LastName As String)
  17.         MyBase.New()
  18.         Me.FirstName = FirstName
  19.         Me.LastName = LastName
  20.     End Sub
  21.  
  22.     ' A read-write property    
  23.     Property Age() As Short
  24.         Get
  25.             Return m_Age
  26.         End Get
  27.         Set(ByVal Value As Short)
  28.             m_Age = Value
  29.         End Set
  30.     End Property
  31.  
  32.     ' A property with arguments
  33.     Property EmailAddress(ByVal Index As Short) As String
  34.         Get
  35.             Return m_EmailAddress(Index)
  36.         End Get
  37.         Set(ByVal Value As String)
  38.             m_EmailAddress(Index) = Value
  39.         End Set
  40.     End Property
  41.  
  42.     ' A method with optional arguments
  43.     Sub SendEmail(ByVal msg As String, Optional ByVal Priority As Integer = 1)
  44.         ' ... (No real code in this demo)...
  45.         Console.WriteLine("Message to " & FirstName & " " & LastName)
  46.         Console.WriteLine("Priority = " & Priority.ToString)
  47.         Console.WriteLine(msg)
  48.     End Sub
  49. End Class
  50.